<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>

<head>
	<base href="<%=basePath%>">
	<title>更新用户</title>
	<script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
	<script type="text/javascript" src="<%=basePath%>dwrsystem/interface/userService.js"></script> 
	<script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/validateJS.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/tableForm.js"></script>
	<script type="text/javascript" src="<%=basePath%>component/jscal.js"></script>
</head>

<body onload="bodyInit()">
	<div id="dataObj">
	<div id="displayDiv" class="formlayout" style="overflow:auto;width:100%;height:100%;">
		<c:if test="${!empty userEdit}">
		<form action="<%=basePath%>system-user/UserAction!userEdit.action" method="post" name="editForm">
			<input type="hidden" name="userForm.userMainId" id="userForm.userMainId" value="${userEdit.userMainId }"/>
			<input type="hidden" name="userForm.loginPassword" id="userForm.loginPassword" />
			<input type="hidden" name="userForm.loginCodePassed" id="userForm.loginCodePassed" value="${userEdit.loginCode }" />
			<table>
				<tr>	
					<th>登录账号</th>
					<td> 
						${userEdit.loginCode }
						<input type="hidden" name="editFormHidden"
						 value="[{type:'input',id:'userForm.loginCode',name:'userForm.loginCode',value:'${userEdit.loginCode }',showText:'${userEdit.loginCode }',maxlength:'25',mustEnter:'yes'}]"/>
					</td>
				</tr>
				<tr>	
					<th>登录姓名</th>
					<td>
						${userEdit.loginName }
						<input type="hidden" name="editFormHidden"
						 value="[{type:'input',id:'userForm.loginName',name:'userForm.loginName',value:'${userEdit.loginName }',showText:'${userEdit.loginName }',maxlength:'25',mustEnter:'yes'}]"/>
					</td>
				</tr>
				<tr>	
					<th>登录密码</th>
					<td>
						******
						<input type="hidden" name="editFormHidden"
						 value="[{type:'customize',showText:'${unitEdit.siteName }',customizeId:'customizeDIV_resetPass'}]"/>
					</td>
				</tr>
				<tr>	
					<th>用户类型</th>
					<td>
					<c:if test="${userEdit.userType eq 1}">普通用户</c:if><c:if test="${userEdit.userType eq 0}">管理员</c:if>
					<input type="hidden" name="editFormHidden"
						value="[{type:'select',id:'userForm.userType',name:'userForm.userType',value:'1&普通用户|0&管理员',defaultSelect:'${userEdit.userType }',
							showText:'<c:if test="${userEdit.userType eq 1}">普通用户</c:if><c:if test="${userEdit.userType eq 0}">管理员</c:if>'}]"/>					
					</td>
				</tr>
				<tr>	
					<th>用户状态</th>
					<td>
						<c:if test="${userEdit.status eq 1}">有效</c:if><c:if test="${userEdit.status eq 0}">无效</c:if>
						<input type="hidden" name="editFormHidden"
							value="[{type:'select',id:'userForm.status',name:'userForm.status',value:'1&有效|0&无效',defaultSelect:'${userEdit.status }',
								showText:'<c:if test="${userEdit.status eq 1}">有效</c:if><c:if test="${userEdit.status eq 0}">无效</c:if>'}]"/>							
					</td>
				</tr>
				<tr>   			
					<th>备注</th>
					<td>
						${userEdit.note }
						<input type="hidden" name="editFormHidden"
						 value="[{type:'textarea',id:'userForm.note',name:'userForm.note',value:'${userEdit.note }',showText:'${userEdit.note }'}]"/>
					</td>
				</tr>
			</table>
		</form>
		</c:if>			
	</div>
	
	<div id="customizeDIV_resetPass" style="display:none;">
		 <input type="text" name="newPassword" id="newPassword" readonly="readonly"/>
		 <button onclick="resetPassword();return false;">重置密码</button>
		 <button onclick="unResetPassword();return false;">取消重置</button>	
	</div>
	
	<form action="" method="post" name="delForm">
		<input type="hidden" name="unitId" id="unitId" value="${unitId }">
		<input type="hidden" name="userMainId" id="userMainId" value="${userEdit.userMainId }"/>
	</form>
	</div>
</body>
	
<script type="text/javascript">
var mytree;
var unitId;
var userId;
var dhxLayout = createLayoutNormal('1C',false,true);

function bodyInit(){
	configLayout();
	userId = '${userEdit.userMainId }';
	mytree = parent.window.MyTree;
	unitId = mytree.getParentNodeId(mytree.getSelectNodeId());
}

function configLayout(){
	var a = dhxLayout.cells('a');
	a.hideHeader();
	a.setText('主页面');
	a.fixSize(true, true);
	if(power.getPower() != '' && (power.getPowerInsert() || power.getPowerDelete()))
		createToolbarFromDHXLayoutCell(a,function(toolbar){
		    toolbar.addText("info", 1, "操作:");
		    toolbar.addSeparator("sep1", 2);
		    if(power.getPowerUpdate()){
		    	toolbar.addButton("update", 4, "修改", "settings.gif", "settings.gif");
		    	toolbar.addButton("submit", 5, "提交", "save.gif", "save_dis.gif");
		    	toolbar.addButton("cancel", 6, "取消", "undo.gif", "undo_dis.gif");
		    	toolbar.hideItem('submit');
		    	toolbar.hideItem('cancel');
		    }
		    if(power.getPowerDelete()){
		    	toolbar.addButton("delete", 7, "删除", "cut.gif", "cut_dis.gif");
		    	toolbar.addButton("deleteDeeper", 8, "彻底删除", "delete.png", "delete.png");
		    }
		    toolbar.attachEvent("onClick", function(id) {
		    	if(id == 'deleteDeeper'){
		    		validateDelAll();
		    	}
		    	if(id == 'delete'){
		    		validateDelUnit();
		    	}
		    	if(id == 'update'){
		    		tableForm.tableToForm();
		    		toolbar.showItem('submit');
		    		toolbar.showItem('cancel');
		    		toolbar.hideItem('update');
		    	}
		    	if(id == 'cancel'){
		    		tableForm.formReturnTable();
		    		toolbar.showItem('update');
		    		toolbar.hideItem('cancel');
		    		toolbar.hideItem('submit');
		    	}
		    	if(id == 'submit'){
		    		validateEdit();
		    	}
		    });
		});
	a.attachObject('dataObj');
}

function resetPassword(){
	document.getElementById('newPassword').value='123456';
}

function unResetPassword(){
	document.getElementById('newPassword').value='';
}

function validateEdit(){
	
	var ulogincode = document.getElementById('userForm.loginCode').value;
	if(trim(ulogincode)==''){parent.parent.parent.notifyWarn('请输入登录账号');return;}
	if (!validatePattern.validateInputZZ(ulogincode,false)){
		parent.parent.parent.notifyWarn('登录账号非法，输入只能是[汉字,数字、26个英文字母或者下划线]');
		return ;
	}
	
	var uloginname = document.getElementById('userForm.loginName').value;
	if(trim(uloginname)==''){parent.parent.parent.notifyWarn('请输入登录名称');return;}
	if (!validatePattern.validateChinese(uloginname,false)){
		parent.parent.parent.notifyWarn('登录名称非法，输入只能是[汉字]');
		return ;
	}

	if(document.getElementById('newPassword').value != ''){
		document.getElementById('userForm.loginPassword').value = document.getElementById('newPassword').value;
	}
	
	layoutProgressOn(dhxLayout);
	userService.selectExistTUserForUpdate({loginCode:ulogincode, userMainId:userId}, function(data){
		if(data == 1){
			parent.parent.parent.notifyWarn('存在相同的登录账号');layoutProgressOn(dhxLayout);
			return;
		}else{
			userService.selectExistTUserForUpdate({loginName:uloginname, userMainId:userId}, function(data){
				if(data == 1){
					parent.parent.parent.notifyWarn('存在相同的登录姓名');layoutProgressOn(dhxLayout);
					return;
				}else{
					document.forms["editForm"].submit();
					if(mytree.getNodeLevel(unitId) == mytree.getNodeLevel(userId) - 1)
						mytree.editNode(userId, uloginname);
				}
			});
		}
	});
	
}

function validateDelUnit(){
	parent.confirmInfo('从当前单位中，删除此用户',
		function(choose){
			if('ok' == choose){
				layoutProgressOn(dhxLayout);
				userService.deleteTUserUnit(userId, unitId, function(data){
					if(data == true){
						parent.parent.notifyCreater('删除用户成功');layoutProgressOff(dhxLayout);
						mytree.delNode(mytree.getSelectNodeId());
					}else{
						parent.parent.notifyWarn('删除用户异常');layoutProgressOff(dhxLayout);return;
					}
				});
			}else{
				return;
			}
		}
	);
}

function validateDelAll(){
	parent.confirmInfo('从系统中，彻底删除此用户',
		function(choose){
			if('ok' == choose){
				layoutProgressOn(dhxLayout);
				userService.deleteTUserAll(userId, function(data){
					if(data == true){
						parent.parent.notifyWarn('删除用户成功');layoutProgressOff(dhxLayout);
						mytree.delNode(mytree.getSelectNodeId());
						//parent.window.location.reload();
					}else{
						parent.parent.notifyWarn('删除用户异常');layoutProgressOff(dhxLayout);
					}
				});
			}else{
				return;
			}
		}
	);
}

</script>
	
</html>
